//
//  UIBarButtonItemCategory.m
//  TestNavi
//
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "UIBarButtonItemCategory.h"
#import "Global.h"

#define UIBarButtonItem_width  44
#define UIBarButtonItem_height 33


@implementation UIBarButtonItem (UIBarButtonItemCategory)
+(UIBarButtonItem*)textBarButtonItem:(NSString*)title target:(id)target action:(SEL)selector {
    if ([Global curLanguageEn]) {
        if ([title isEqualToString:STR(@"保存")]) {
            title = @"Save";
        }
    }
    //48*31 10
    UIButton *btnView=[UIButton buttonWithType:UIButtonTypeCustom];
    CGFloat width=[title sizeWithFont:[UIFont boldSystemFontOfSize:13]].width;
    if (width<33) {
        width=33;
    }
    btnView.frame=CGRectMake(0, 0, width+20, UIBarButtonItem_height);
    [btnView.titleLabel setFont:[UIFont boldSystemFontOfSize:13]];
    
    [btnView setBackgroundImage:[[UIImage imageNamed:@"navi_btn_default_bg.png"] stretchableImageWithLeftCapWidth:31 topCapHeight:0] forState:UIControlStateNormal];

    [btnView setTitle:title forState:UIControlStateNormal];
    
    btnView.titleLabel.shadowColor=[UIColor blackColor];
    btnView.titleLabel.shadowOffset=CGSizeMake(0, -1);
    
    UIBarButtonItem *barButtonItem=[[[UIBarButtonItem alloc] initWithCustomView:btnView] autorelease];
    [btnView addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
    return barButtonItem;
    
}

+(UIBarButtonItem*)textBarButtonItem:(NSString*)title backgroundImage:(UIImage*)bgImage target:(id)target action:(SEL)selector {
    //48*31 10
    UIButton *btnView=[UIButton buttonWithType:UIButtonTypeCustom];
    CGFloat width=[title sizeWithFont:[UIFont boldSystemFontOfSize:13]].width;
    if (width<33) {
        width=33;
    }
    btnView.frame=CGRectMake(0, 0, width+20, UIBarButtonItem_height);
    [btnView.titleLabel setFont:[UIFont boldSystemFontOfSize:13]];
    
    
    [btnView setBackgroundImage:[bgImage stretchableImageWithLeftCapWidth:31 topCapHeight:0] forState:UIControlStateNormal];
    
    [btnView setTitle:title forState:UIControlStateNormal];
    
    btnView.titleLabel.shadowColor=[UIColor blackColor];
    btnView.titleLabel.shadowOffset=CGSizeMake(0, -1);
    
    UIBarButtonItem *barButtonItem=[[[UIBarButtonItem alloc] initWithCustomView:btnView] autorelease];
    [btnView addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
    return barButtonItem;
    
}


+(UIBarButtonItem*)imageBarButtonItem:(UIImage*)image target:(id)target action:(SEL)selector {
    //48*31 10
    UIButton *btnView=[UIButton buttonWithType:UIButtonTypeCustom];

    btnView.frame=CGRectMake(0, 0, UIBarButtonItem_width, UIBarButtonItem_height);
    [btnView setImage:image forState:UIControlStateNormal];
    UIBarButtonItem *barButtonItem=[[[UIBarButtonItem alloc] initWithCustomView:btnView] autorelease];
    [btnView addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
    return barButtonItem;
    
}



+(UIBarButtonItem*)backImageBarButtonItem:(UIImage*)image target:(id)target action:(SEL)selector {
    //48*31 10
    UIButton *btnView=[UIButton buttonWithType:UIButtonTypeCustom];
    
    btnView.frame=CGRectMake(0, 0, UIBarButtonItem_width, UIBarButtonItem_height);
    [btnView setImage:image forState:UIControlStateNormal];
    UIBarButtonItem *barButtonItem=[[[UIBarButtonItem alloc] initWithCustomView:btnView] autorelease];
    [btnView addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
    return barButtonItem;
    
}

+(UIBarButtonItem*)backBarButtonItemWithTarget:(id)target action:(SEL)selector {
    //48*31 10
    UIButton *btnView=[UIButton buttonWithType:UIButtonTypeCustom];
    btnView.frame=CGRectMake(0, 0, UIBarButtonItem_width, UIBarButtonItem_height);
    [btnView setImage:[UIImage imageNamed:@"toolbar_icon_back.png"] forState:UIControlStateNormal];
    UIBarButtonItem *barButtonItem=[[[UIBarButtonItem alloc] initWithCustomView:btnView] autorelease];
    [btnView addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
    return barButtonItem;
    
}

-(void)dealloc {
    [super dealloc];
}

@end
